package demo1;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created with Intellij IDEA.
 * Description:
 * User: 33013
 * Date: 2023-09-06
 * Time: 22:55
 */
public class Test2 {
    public static void duplicateZeros(int[] arr) {
        int len = arr.length;
        int right = 0, left = 0;
        for(left = 0, right = 0; right < len;){
            if(arr[left] == 0){
                right++;
                right++;
            }else {
                right++;
            }
            if(right >= len){
                break;
            }
            left++;
        }
        if(right == len + 1){
            arr[len - 1] = 0;
            right = len - 2;
            left--;
        }else{
            right = len - 1 ;
        }
        while(left >= 0){
            if(arr[left] == 0){
                arr[right--] = 0;
                arr[right--] = 0;
            }else{
                arr[right] = arr[left];
                right--;
            }
            left--;
        }
    }

    public static int triangleNumber(int[] nums) {
        Arrays.sort(nums);
        int left = 0, right = 0,max = nums.length - 1, n = max - 2, ret = 0;
        for(int i = 0; i <= n; i++){
            left = 0;
            right = n - i;
            int lon = nums[max - i];
            while(left < right){
                if(nums[left] + nums[right] > lon){
                    ret += (right - left);
                    right--;
                }else{
                    left++;
                }

            }
        }
        return ret;
    }

    private static Object object = new Object();

    public synchronized void print(){
        synchronized (this){
            System.out.println("hahha");
        }
    }

    public static void main(String[] args) {
//        int[] arr = {8,4,5,0,0,0,0,7};
//        duplicateZeros(arr);
//        Arrays.sort(arr);
//        System.out.println(Arrays.toString(arr));
        int[] arr = {2,2,3,4};
        triangleNumber(arr);
        List<Integer> list = new ArrayList<>();
        list.ad
    }
}
